package com.ruoyi.web.controller.car;

import java.util.List;

import com.ruoyi.system.service.ICarinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Carinfo;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 车辆 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/carinfo")
public class CarinfoController extends BaseController
{
    private String prefix = "system/carinfo";
	
	@Autowired
	private ICarinfoService carinfoService;
	
	@RequiresPermissions("system:carinfo:view")
	@GetMapping()
	public String carinfo()
	{
	    return prefix + "/carinfo";
	}
	
	/**
	 * 查询车辆列表
	 */
	@RequiresPermissions("system:carinfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Carinfo carinfo)
	{
		startPage();
        List<Carinfo> list = carinfoService.selectCarinfoList(carinfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出车辆列表
	 */
	@RequiresPermissions("system:carinfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Carinfo carinfo)
    {
    	List<Carinfo> list = carinfoService.selectCarinfoList(carinfo);
        ExcelUtil<Carinfo> util = new ExcelUtil<Carinfo>(Carinfo.class);
        return util.exportExcel(list, "carinfo");
    }
	
	/**
	 * 新增车辆
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存车辆
	 */
	@RequiresPermissions("system:carinfo:add")
	@Log(title = "车辆", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Carinfo carinfo)
	{		
		return toAjax(carinfoService.insertCarinfo(carinfo));
	}

	/**
	 * 修改车辆
	 */
	@GetMapping("/edit/{carinfoId}")
	public String edit(@PathVariable("carinfoId") Integer carinfoId, ModelMap mmap)
	{
		Carinfo carinfo = carinfoService.selectCarinfoById(carinfoId);
		mmap.put("carinfo", carinfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存车辆
	 */
	@RequiresPermissions("system:carinfo:edit")
	@Log(title = "车辆", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Carinfo carinfo)
	{		
		return toAjax(carinfoService.updateCarinfo(carinfo));
	}
	
	/**
	 * 删除车辆
	 */
	@RequiresPermissions("system:carinfo:remove")
	@Log(title = "车辆", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(carinfoService.deleteCarinfoByIds(ids));
	}

	/**
	 *  修改车辆状态
	 * @param carinfo
	 * @return 结果
	 */
	@Log(title = "车辆状态修改", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:carinfo:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Carinfo carinfo)
	{
		return toAjax(carinfoService.updateCarinfo(carinfo));
	}
	
}
